var Permission = {};
// eslint-disable-next-line func-names
Permission.install = function(Vue, options) {
  /**
   * 权限指令
   */
  Vue.directive('permission', {
    // 判断按钮是否有权限,支持Number，Array
    inserted: (el, binding) => {
      if (binding.value) {
        const pathIds = this.$store.getters['user/pathIds'];
        const { value } = binding;

        let isPermission = false;
        if (value instanceof Array) {
          // 是否包含
          if (value.every(item => pathIds.includes(item))) {
            isPermission = true;
          }
        } else if (pathIds.includes(value)) {
          isPermission = true;
        }
        if (!isPermission) {
          el.parentNode.removeChild(el);
        }
      }
    }
  });
  /**
   * 添加permission方法
   * return Bool
   */
  // eslint-disable-next-line func-names
  Vue.prototype.$permission = function(value) {
    const pathIds = this.$store.getters['user/pathIds'];

    let isPermission = false;
    if (value instanceof Array) {
      // 是否包含
      if (value.every(item => pathIds.includes(item))) {
        isPermission = true;
      }
    } else if (pathIds.includes(value)) {
      isPermission = true;
    }
    return isPermission;
  };
};
export default Permission;
